﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RaygunDiplomacy.Model.Terrain.Local;

namespace RaygunDiplomacy.ViewModel.Isometric
{
   public static class IsoCameraExtensions
   {
      public static SpatialIndex GetChunkIndex(this IsoCamera camera)
      {
         SpatialIndex index = new SpatialIndex(
            (int)(camera.Focus.X / ChunkCells.ChunkSize),
            (int)(camera.Focus.Y / ChunkCells.ChunkSize),
            (int)(camera.Focus.Z / ChunkCells.ChunkSize));

         return index;
      }

      public static SpatialIndex GetCellIndex(this IsoCamera camera)
      {
         var chunkIndex = camera.GetChunkIndex();

         SpatialIndex index = new SpatialIndex(
            (int)(camera.Focus.X - ChunkCells.ChunkSize * chunkIndex.Row),
            (int)(camera.Focus.Y - ChunkCells.ChunkSize * chunkIndex.Column),
            (int)(camera.Focus.Z - ChunkCells.ChunkSize * chunkIndex.Layer));

         return index;
      }
   }
}
